﻿@using SmartStore.Web.Models.Boards;
@using SmartStore.Web.Framework.UI;
@model ActiveDiscussionsModel
@{ 
    var isPartial = Model.ViewAllLinkEnabled;
}

@if (!isPartial)
{
    <div class="mt-2 w-75">
        @{ Html.RenderAction("SearchBox", "Boards"); }
    </div>
}

<div class="active-discussions mt-5">
    <div class="row">
        <div class="col">
            <div class="heading mb-4">
                <h3 class="heading-title @(!isPartial ? "fs-h1" : "")">@T("Forum.ActiveDiscussions")</h3>
            </div>
        </div>
        <div class="col col-auto mb-3 mb-0-sm">
            @if (Model.ActiveDiscussionsFeedEnabled == true)
            {
                <a class="btn btn-warning" href="@Url.Action("ActiveDiscussionsRSS")" title="@T("Forum.ActiveDiscussionsRSSLinkTitle")">
                    <i class="fa fa-rss"></i>
                    <span>@T("Forum.RSS")</span>
                </a>
            }
            
            @if (isPartial)
            {        
                <a class="btn btn-outline-info btn-flat" href="@Url.Action("ActiveDiscussions")">
                    <i class="fa fa-th-list"></i>
                    <span>@T("Forum.ActiveDiscussions.ViewAll")</span>
                </a>
            }
        </div>
    </div>

    <div class="active-discussionstopics table-responsive clearfix">
        <table class="table">
            @if (Model.ForumTopics.Count > 0)
            {
                <thead>
                    <tr class="active-discussions-header">
                        <th></th>
                        <th class="topic-name">
                            @T("Forum.TopicTitle")
                        </th>
                        <th class="replies d-none d-md-table-cell">
                            @T("Forum.Replies")
                        </th>
                        <th class="views d-none d-md-table-cell">
                            @T("Forum.Views")
                        </th>
                        <th class="last-post d-none d-md-table-cell">
                            @T("Forum.LatestPost")
                        </th>
                    </tr>
                </thead>
            }

            @foreach (var topic in Model.ForumTopics)
            {
                <tr class="topic">
                    <td class="image">
                        @{ Html.RenderPartial("Customer.Avatar", topic.Avatar); }
                    </td>
                    <td class="topic-name">
                        @Html.RouteLink(topic.Subject, "TopicSlug", new { id = topic.Id, slug = topic.SeName }, new { @class = "topic-title" })
                        <div>
                            <div class="topic-starter text-muted pull-left d-inline-flex">
                                @if (topic.CustomerId > 0)
								{
									<span class="pr-1">@T("Forum.Author"):</span>

									var authorText = T("Forum.Author");

									if (topic.AllowViewingProfiles && !topic.IsCustomerGuest)
									{
										<span>@Html.RouteLink(topic.CustomerName, "CustomerProfile", new { Id = topic.CustomerId })</span>
									}
									else
									{
										<span>@topic.CustomerName</span>
                                    }
                                }
                            </div>

                            @if (@topic.NumPosts > Model.PostsPageSize)
                            {
                                @(Html.SmartStore().Pager(topic.TotalPostPages)
                                    .QueryParam("page")
                                    .HtmlAttributes(new { @class = "topics-pager" })
                                    .WithRenderer<ForumTopicPagerRenderer>()
                                    .ShowPrevious(false)
                                    .ShowNext(false)
                                    .ItemTitleFormatString(T("Forum.Topics.GotoPostPager"))
                                    .Alignment(PagerAlignment.Left)
                                    .Size(PagerSize.Mini)
                                    .Route("TopicSlug", new { id = topic.Id, slug = topic.SeName }))
                            }
                        </div>
                    </td>
                    <td class="replies d-none d-md-table-cell">
                        @topic.NumReplies.ToString("N0")
                    </td>
                    <td class="views d-none d-md-table-cell">
                        @topic.Views.ToString("N0")
                    </td>
                    <td class="last-post d-none d-md-table-cell">
                        @{ Html.RenderPartial("LastPost", topic.LastPost); }
                    </td>
                </tr>
            }
        </table>
    </div>
</div>
